<?php
namespace XtwsAdmin\Controller;
use Think\Controller;

class IndexController extends CommonController {

    public function index(){
        $this->display();
    }//end fun


    // 退出登录
    public function logout(){
        // 清除sesssion中的管理员id
        session('zx_admin.user_id',null);
        $this->redirect('/XtwsAdmin/Login/index');
    }//end fun

    //修改密码
    public function changepw(){
        if(IS_POST){
            //接收用户输入的密码
            $oldpw = md5(I('oldpw'));
            $newpw = md5(I('newpw'));
            if($oldpw == $newpw){
                $this->error('两次密码相同！');
            }
            //查询数据表中对应的数据
            $id= session ('bc_admin.user_id');
            $bc_admin = M('bc_admin');  //实例化
            $uInfo = $bc_admin->where(array('id'=>$id))->find();
            if($uInfo['upwd']!=$oldpw){
                $this->error('旧密码错误！');
            }
            $uInfo['upwd'] = $newpw;
            $status = $bc_admin->save($uInfo);
            if(is_numeric($status)){
                $this->success('修改成功！');
            }else{
                $this->error('修改失败！');
            }
        }//end if
    }//end fun



}//end class